/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[WrapperClasses.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package jdk5;

/**
 * 封装类
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class WrapperClasses {

	/**
	 * java.lang.Boolean测试
	 */
	public static void testBoolean() {

		boolean b = true;

		/*
		 * 采用boolean构建封装类
		 */
		Boolean b1 = new Boolean(b);
		System.out.println("Boolean value = " + b1);

		/*
		 * 采用字符串类构建封装类, 如果字符串的字面值不区分大小写为"true", 那么封装类的值为true, 否则为false
		 */
		Boolean b2 = new Boolean("TrUe");
		System.out.println("new Boolean(\"TrUe\") = " + b2);
		Boolean b3 = new Boolean("1234");
		System.out.println("new Boolean(\"1234\") = " + b3);
	}

	/**
	 * java.lang.Integer测试
	 */
	public static void testInteger() {
		Integer i1 = new Integer(100);
		Integer i2 = new Integer("200");
		// 自动拆箱
		System.out.println("i1 + i2 = " + (i1 + i2));

		Integer i3 = 100; // 自动装箱
		Integer i4 = Integer.valueOf("100");
		// 自动拆箱
		System.out.println("i3 + i4 = " + (i3 + i4));

		/*
		 * Integer池[-128~127], Integer的equals方法被重写过, 比较的是内容
		 */
		Integer i5 = 100;
		Integer i6 = 100;
		System.out.println("i5 == i6 = " + (i5 == i6));
		System.out.println("i5.equals(i6) = " + i5.equals(i6));

		Integer i7 = new Integer(100);
		Integer i8 = new Integer(100);
		System.out.println("i7 == i8 = " + (i7 == i8));
		System.out.println("i7.equals(i8) = " + i7.equals(i8));

		Integer i9 = 200;
		Integer i10 = 200;
		System.out.println("i9 == i10 = " + (i9 == i10));
		System.out.println("i9.equals(i10) = " + i9.equals(i10));

		Integer i11 = new Integer(200);
		Integer i12 = new Integer(200);
		System.out.println("i11 == i12 = " + (i11 == i12));
		System.out.println("i11.equals(i12) = " + i11.equals(i12));

		System.out.println("Integer.MAX_VALUE=" + Integer.MAX_VALUE);
		System.out.println("Integer.MIN_VALUE=" + Integer.MIN_VALUE);
		System.out.println("Integer.SIZE=" + Integer.SIZE);

		Integer i15 = new Integer(12);
		int i = i15.intValue();
		System.out.println(i);

		String str = i15.toString();
		String binaryStr = Integer.toBinaryString(i15);
		String octalStr = Integer.toOctalString(i15);
		String hexStr = Integer.toHexString(i15);
		System.out.println("十进制表示: " + str);
		System.out.println("二进制表示: " + binaryStr);
		System.out.println("八进制表示: " + octalStr);
		System.out.println("十六进制表示: " + hexStr);

		System.out.println("转换字符串到Integer: " + Integer.parseInt("10000"));
	}

	/**
	 * java.lang.Double测试
	 */
	public static void testDouble() {
		Double.isInfinite(2.0 / 0.0);
		Double.isNaN(0.0 / 0.0);
	}

	/**
	 * 将float转换为int
	 * 
	 * @param f
	 *            要转换的float值
	 * @return 转换后的int值
	 */
	public static int convertFloatToInteger(float f) {
		Integer i5 = new Integer(new String(f + "").split("\\.")[0]);
		i5 = new Integer(new Float(f).intValue());
		return i5.intValue();
	}

	public static void main(String[] args) {
		testBoolean();
		testInteger();
		testDouble();
	}
}
